/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
    Button, TextArea, Text, useToast, InputLine, SuffixInput,
} from "customize-easy-ui-component";
import {InspectRecordLayout, InternalItemProps, useItemInputControl} from "../../common/base";
import {useMedia} from "use-media";
import {assertNamesUnique} from "../../common/eHelper";
import {EditStorageContext} from "../../StorageContext";
import {itemA下结论} from "../external/editor";
import {itemA缺陷问题} from "./editDefect";
import {itemA简图} from "./editSimpic";
import {itemA元件} from "./editPresCm";
import {itemA资料查阅} from "./MaterialReview";
import {itemA宏观检查} from "./Macroscopic";
import {itemA部件图} from "../editorLineDg";
import {itemA大板梁} from "./LargeSlabBeam";
import {itemA联络附页} from "./DrawingsExplan";

const input工作温={
    edit:(inp:any,setInp:(a:any)=>void)=>{
        return <div><Text css={{fontSize:'0.7rem'}}>后续1个参数属性能参数：</Text>
            <InputLine  label='性能参数 > 锅筒工作温度'>
                <SuffixInput  value={inp?.筒工温 ||''}
                              onChange={e => setInp({...inp, 筒工温: e.currentTarget.value || undefined}) }>℃</SuffixInput>
            </InputLine>
        </div>;
    },
    //names: ['设计温','壳程设计温度'],       toTail: '设计温度太多了需要另行设定',
};
export const config设备概况 = [
    [['锅炉型号', '_$型号'], ['设备代码', '_$设备代码', ], ],
    [['产品编号', '_$出厂编号'], ['单位内编号', '_$单位内部编号'] ],
    [['制造单位', '_$制造单位'], ],
    [['安装单位', '_$安装单位'], ],
    [['产权单位', '_$产权单位'] ],
    [['使用单位', '_$使用单位'], ],
    [['设备使用地点', '_$设备使用地点'],  ],
    [['使用单位统一社会信用代码','_$使用单位信用码'], ['邮政编码', '_$使用单位邮编'] ],
    [['使用登记证编号', '_$使用证号'], ['投入使用日期', '_$投用日期'], ],
    [['累计运行小时', {n:'累运行',u:'h'}, ], ['上次检验日期', {n:'上检日',t:'d'} ],  ],
    //还有一种 prview: 的回调做法？ 涉及台账两个参数 {orc.是功率 ? 'MW' : 't/h'}
    [ [{pr:'性能参数', span:6, t:'额定蒸发量'}, '_$额定蒸发量', 't/h'],   ['再热蒸汽流量', '_$再热蒸汽流量','t/h'],  ],
    //锅筒工作温度？ 台账没有等同的参数？
    [[{t:'锅筒工作压力'}, '_$锅筒工作压力', 'MPa'],  ['锅筒工作温度',{n:'筒工温', u:'℃'}, input工作温],   ],
    [[{t:'过热器出口压力'},'_$过热器出口压', 'MPa'],  ['过热器出口温度','_$过热器出口温', '℃'],  ],
    [[{t:'再热器出口压力'},'_$再热出口压力', 'MPa'],  ['再热器出口温度','_$再热出口温度', '℃'],  ],
    [[{t:'再热器进口压力'},'_$再热入口压力', 'MPa'],  ['再热器进口温度','_$再热入口温度', '℃'],  ],
    // [['性能参数第一条是额定功率的吗',{n:'是功率',t:'b'}] ],
    [[{t:'给水压力'},'_$给水压力', 'MPa'],  ['给水温度','_$给水温度', '℃'],  ],
];

export const EntranceSetup =
    React.forwardRef((
        {children, show, alone = true, repId, verId, rep}: InternalItemProps, ref
    ) => {
        const atPrint = useMedia('print');
        const toast = useToast();
        const doCheckNames = React.useCallback((verId: string) => {
            const result = assertNamesUnique([{value: rep?.tzFields},
                {value: config设备概况, type:'esnt'},
                {value:[...itemA下结论, ...itemA缺陷问题, ...itemA简图, ...itemA元件, ...itemA资料查阅, ...itemA宏观检查 ]},
                {value:[...itemA部件图, ...itemA大板梁, ...itemA联络附页 ]},
                {value:['Projects', '挠度表', '尺寸表', '割管表', '联络单']}
                ]);
            toast({title: "完成！", subtitle: result ? "没发现冲突" : "测试开关没开", intent: "success"});
        }, [rep,toast]);
        const {storage, setStorage} =React.useContext(EditStorageContext) as any;
        const getInpFilter = React.useCallback((par: any) => {
            const {_tblFixed, } =par||{};
            return {_tblFixed, };
        }, []);
        const {inp, setInp} = useItemInputControl({ref});
        if (atPrint) return null;
        else return (
            <InspectRecordLayout inp={inp} setInp={setInp} getInpFilter={getInpFilter} show={show}
                                 alone={alone} label={'初始化本报告，默认值配置等'}>
                {process.env.REACT_APP_TEST==='true' && <><div>
                    <Text variant="h5">构建开发模板时的工具：校验模板的存储name冲突；</Text>
                    <Button intent='primary' onPress={() => doCheckNames(verId!)}>校验模板name唯一性</Button>
                    <Text variant="h5">设置待测试表格的各列宽度：</Text>
                    <TextArea value={storage?._tblFixed || ''} rows={2} onChange={e =>{
                        JSON.parse(e.currentTarget.value??'[]');
                        setStorage({ ...storage, _tblFixed: e.currentTarget.value || undefined}); }}/>
                </div></>
                }
                <hr/>
            </InspectRecordLayout>
        );
    });
